#include <iostream>
#include <map>
#include <string>
using namespace std;
const int N = 100;
bool vis[N], in[N];
int cnt, n, ans;
int son[N];
bool ins[N];
map< string, int > m;
bool dfs(int x) {
	if (son[x] == 0) return false;
	if (ins[x]) return true;
	vis[x] = true;
	ins[x] = true;
	bool tmp = dfs(son[x]);
	ins[x] = false;
	return tmp;
}
int main() {
#ifndef ONLINE_JUDGE
#ifdef DEBUG
	freopen("testdata.in", "r", stdin);
	freopen("testdata.out", "w", stdout);
#endif
#ifndef DEBUG
	freopen("files.in", "r", stdin);
	freopen("files.out", "w", stdout);
#endif
#endif
	string tmp, tmp2;
	cin >> n;
	ans = n;
	for (int i = 0; i < n; ++i) {
		cin >> tmp >> tmp2;
		if (m.find(tmp) == m.end()) m[tmp] = ++cnt;
		if (m.find(tmp2) == m.end()) m[tmp2] = ++cnt;
		if (tmp == tmp2) {
			ans--;
			continue;
		}
		son[m[tmp]] = m[tmp2];
	}
	for (int i = 1; i <= cnt; ++i) {
		if (!vis[i])
			if (dfs(i)) ans++;
	}
	cout << ans;
}
